/*
ID:luongho3
LANG:C++
TASK:spin
*/
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("spin.in");
ofstream fout("spin.out");
#define NWHEEL 5
#define NWEDGE 5
struct Wedge{
       int degree;
       int extent;
};
struct Wheel{
       int speed;
       int nwedge;
       Wedge wedges[NWEDGE+1];
};
Wheel wheels[NWHEEL+1];
bool wedges_aligned(Wedge w1, Wedge w2) {
     if ((w1.degree % 360) == (w2.degree % 360)) {
        return true;
     }
     if (((w1.degree + w1.extent) % 360) == ((w2.degree + w2.extent) % 360)) {
        return true;
     }
     if (((w1.degree + w1.extent) % 360) == (w2.degree % 360)) {
        return true;
     }
     if ((w1.degree % 360) == ((w2.degree + w2.extent) % 360)) {
        return true;
     }
     return false;
}
bool wheels_aligned(Wheel w1, Wheel w2) {
     int i,j;
     for (i=1;i<=w1.nwedge;++i) {
         for (j=1;j<=w2.nwedge;++j) {
             if (wedges_aligned(w1.wedges[i], w2.wedges[j])==true) {
                return true;
             }
         }
     }
     return false;
}
void load_wheels() {
     int i,j;
     for (i=1;i<=NWHEEL;++i) {
         fin >> wheels[i].nwedge;
         for (j=1;j<=wheels[i].nwedge;++j) {
             fin >> wheels[i].wedges[j].degree>> wheels[i].wedges[j].extent;
         }
     }
}
int main() {
    load_wheels();
    int nsec = 0;
    for (nsec=0;nsec<360;++nsec) {
        
    }
    if (nsec==360) {
       fout << "none\n";
    }
    else {
         fout << nsec << "\n";
    }
    return 0;
}
